//
//  StatisticViewModel.m
//  CityFire
//
//  Created by liuyangzhu on 2017/8/16.
//  Copyright © 2017年 刘养柱. All rights reserved.
//

#import "StatisticViewModel.h"
#import "NSUserDefaults+Tools.h"
#import "UserInfoModel.h"

@implementation StatisticViewModel

- (void)getWarnStatistic:(NSDictionary *)parameter
{
    UserInfoModel *model = [NSKeyedUnarchiver unarchiveObjectWithData:[NSUserDefaults readUserDataWithKey:kNSUSERDEFAULT_KEY_USERINFO]];
    if (model) {
        [YQNetworking requestWithUrl:kWARNING_Statistic_URL requestType:YQHttpRequestTypePOST refreshRequest:YES cache:NO params:@{@"sessionid" :model.seeeionID, @"username" : model.userName, @"daytype" : parameter[@"daytype"], @"start_time" : parameter[@"start_time"], @"end_time" : parameter[@"end_time"]} progressBlock:^(int64_t bytesRead, int64_t totalBytes) {
            //        username=admin&daytype=1&start_time=20170705&end_time=20170805
            
        } successBlock:^(id response, NSError *responseInfo) {
            
            NSError *error;
            StatisticModel *stModel = [MTLJSONAdapter modelOfClass:[StatisticModel class] fromJSONDictionary:response error:&error];
            
            self.responseInfo = error ? error : responseInfo;
            self.statisticModel = stModel;
            
            if (responseInfo.code == 0) {
                //            [NSUserDefaults removeUserDataWithkey:kNSUSERDEFAULT_KEY_SESSIONID];
                //            [NSUserDefaults removeUserDataWithkey:kNSUSERDEFAULT_KEY_USERINFO];
            }else {
                [SVProgressHUD showSuccessWithStatus:responseInfo.domain];
            }
            
        } failBlock:^(NSError *error) {
            self.requestError = error;
            [SVProgressHUD showSuccessWithStatus:error.domain];
        }];
    }
    

}

@end
